package com.kaiyidiannao.activity.foodpalace;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.*;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.*;
import com.baidu.location.BDLocation;
import com.baidu.mapapi.map.*;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.kaiyidiannao.adapter.FoodPalaceAdapter;
import com.kaiyidiannao.adapter.PalyListAdapter;
import com.kaiyidiannao.common.BaseActionBarActivity;
import com.kaiyidiannao.common.pulltorefresh_view.DragListView;
import com.kaiyidiannao.common.util.AppUtils;
import com.kaiyidiannao.common.util.BdMapLocationUitls;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.PlayBean;
import com.kaiyidiannao.view.ActionBarView;
import com.kaiyidiannao.view.AutoTextView;
import com.kaiyidiannao.view.EditTextWithDel;
import com.taplinker.core.util.LogUtil;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by 李奇 on 2014/4/9.
 */
public class FoodPalaceActivity extends BaseActionBarActivity implements View.OnClickListener {
    public boolean isFinish = true;//是否刷新完毕
    public static final int MODULE_FOOD_PALACE = 1;
    public static final int MODLUE_BUY_STREET = 2;
    public static final int MODLUE_PLAY = 3;
    private int module_type = 1;
    private int refresh = 0;
    private int index = 1;
    private boolean flag = false ;
    private static final String TAG = "FoodPalaceActivity";
    private ListView lv;
    private TextView tv;
    private ImageView imageView;
    private BaseAdapter adapter = null;
    private ArrayList<PlayBean> targetList;//类表数据
    private DragListView listView;
    private ProgressBar progressBar;
    private AutoTextView mTextView02;
    private String searchKey = "";
    private String sortby = "distance:1";
    private static final String[] fanweis = {"1000米以内", "2000米以内", "3000米以内", "4000米以内", "5000米以内"};
    private static final String[] highComment = {"评价从高到低", "评价从低到高"};
    private int fanwei = 0;
    private String location;
    private EditTextWithDel search_with_del;
    private ImageButton search_confim_button; //商家搜索对应的连个组件
    private ImageButton backImageButton;//返回按钮

    private Drawable mark1;

    private CheckBox checkbox_category;//展开分类的checkbox
    private View no_content_view;//没有数据的布局对象

    //请求数据参数
    private int catid = DataCenter.foodPalace_category_id[0];
    private int currentPage = DataCenter.LISTVIEW_BAIDU_DEFAULT_PAGE;


    //最新分类样式
    private ListView categoryListview;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, String>> data;
    private View itemParent;

    private String ak = "kFihD1CLl3Sru4dNpdOvQ5RV"; // 这里是后台的key，不是android客户端的key

    private String mid;
    //凑对去，地步滑动导航用菜单
    private LinearLayout menuContainer;
    private View menuBgVew;
    private int preSelectMenuIndex;
    private int view_id;
    private String radius = "5000";
    private String level = "1";
    private boolean isClose = true;//开启分类条
    private int serachFlag = 0; //搜索框标示, 1:表示搜索框开启
    private boolean switchFlag = true; //切换列表页和地图的标示，true：点击图标切换到地图页面
    private int firstIn = 0;//表示第一次进入;让分类列表不进入displayPoi()
    private int isFirst = 0;//表示第一次进入；
    private LinearLayout linerLayout;
    private EditTextWithDel editTextWithDel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.foodpalace);
        // 添加观察者
        mapView = (MapView) findViewById(R.id.baiduMapsView);
        mapController = mapView.getController();
        module_type = getIntent().getIntExtra("module_type", MODULE_FOOD_PALACE);
        selectModuleCatId(0);
        findviews();
        //处理ActionBar
        findActionBar();
        //最新分类
        initCategoryData();
        initCategoryView();
        //加载底部导航
        initBottomMneu();
//        actionBarView.setTitle(data.get(0).get("title").replace("...", ""));
        actionBarView.setTitle("分类");
        listView.setVisibility(View.GONE);
        no_content_view.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
        //百度定位测试
        if (!HttpUtils.isConnected()) {
            Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
            return;
        }
        if (DataCenter.nowLatitude == null || DataCenter.nowLongitude == null || TextUtils.isEmpty(DataCenter.currentAddress)) {
            showProgressDialog("正在定位中...");
            test();
        } else {
            locationSuccess();
        }
        linerLayout = (LinearLayout) findViewById(R.id.linerLayout);
        AppUtils.setupUI(linerLayout, this);
    }


    private void test() {
        //百度定位测试
        final BdMapLocationUitls locationUitls = new BdMapLocationUitls();
        locationUitls.startLocation();
        locationUitls.setListenter(new BdMapLocationUitls.LocationListenter() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
                if(!HttpUtils.isConnected()){
                    closeProgressDialog();
                    locationUitls.stopLocation();
                    Toast.makeText(FoodPalaceActivity.this,"连接网络异常,请稍后重试...",Toast.LENGTH_SHORT).show();
                    return;
                }
                if (bdLocation != null) {
                    String curAddress = bdLocation.getAddrStr(); // 地理位置
                    if (curAddress != null && !curAddress.trim().isEmpty()) {
//                        showToast("定位成功：location:" + curAddress);
                        DataCenter.nowLatitude = bdLocation.getLatitude();
                        DataCenter.nowLongitude = bdLocation.getLongitude();
                        DataCenter.currentAddress = curAddress;
                        locationUitls.stopLocation();
                        locationSuccess();
                    }
                }
            }
        });
    }

    /**
     * 定位成功干的事情
     */
    private void locationSuccess() {
        closeProgressDialog();
        location = DataCenter.nowLongitude + "," + DataCenter.nowLatitude;
        showCurrentProgressView();
//        new GetPlayLIst(mid, ak, "59254", location, radius, currentPage + "").execute();
//        //定位成功
//        new GetPlayLIstTop(1,"1",mid+"",ak,"59254",location,radius).execute();
        searchPoi(ak, location, radius, "1", mid);
        searchPoi1(radius, catid, currentPage, "edittime:-1");
    }


    private void searchPoi(String ak, String location, String radius, String level, String mid) {

        String url = DataCenter.GET_BAIDU_ADDRESS;

        ArrayList<NameValuePair> getParams = new ArrayList<NameValuePair>();
        getParams.add(new BasicNameValuePair("ak", ak));
        getParams.add(new BasicNameValuePair("location", location));
//        getParams.add(new BasicNameValuePair("range", "5000"));
        getParams.add(new BasicNameValuePair("filter", "level:" + Integer.parseInt(level) + "," + Integer.parseInt(level) + "|status:" + 3 + "," + 3 + "|mid:" + mid + "," + mid));
        getParams.add(new BasicNameValuePair("geotable_id", "59254"));
        String getParamsStr = URLEncodedUtils.format(getParams, "UTF-8");
        Log.d(getClass().getName(), "getParamsStr " + getParamsStr);
        url += "?" + getParamsStr;
        final String urll = url;
        Log.d("FoodPalaceActivity",urll +"------------------" + mid);
        try {


            AsyncTask<Integer, Integer, Integer> task = new AsyncTask<Integer, Integer, Integer>() {
                @Override
                protected Integer doInBackground(Integer... params) {
                    try {
                        final HttpGet request = new HttpGet(urll);
                        final DefaultHttpClient client = new DefaultHttpClient();
                        client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
                        HttpResponse response = client.execute(request);
                        String resultJsonStr = EntityUtils.toString(response.getEntity());
                        code1 = response.getStatusLine().getStatusCode();
                        Log.d(getClass().getName(), "Response json " + resultJsonStr);
                        Log.e("HttpClient",code1+"----------");
                        if(code1!=200){
                            return 1;
                        }
                        Log.d(getClass().getName(), "Response json " + resultJsonStr);

                        JSONObject rootJsonObject;
                        rootJsonObject = new JSONObject(resultJsonStr);
                        JSONArray jsonArray = rootJsonObject.optJSONArray("contents");
                        ArrayList<PlayBean> targetList;
                        try {
                            targetList = DataCenter.playTopBeansTopList;
                        } catch (IndexOutOfBoundsException e) {
                            return 1;
                        }
                        targetList.clear();

                        for (int i = 0; i < jsonArray.length(); ++i) { // i从1开始，屏蔽提示信息
                            JSONObject o = jsonArray.getJSONObject(i);
                            PlayBean bean = new PlayBean();
                            bean.setSize(jsonArray.length() + "");
                            try {
                                bean.setThumb(o.getString("thumb"));
                            } catch (JSONException e) {

                            }
//                bean.setStar(o.getString("star"));
                            bean.setTitle(o.getString("title"));
                            bean.setAddress(o.getString("address"));
                            bean.setDistance(o.getString("distance"));
                            bean.setWeight(o.getString("weight"));
                            bean.setItemid(o.getString("itemid"));
                            bean.setCatid(o.getString("catid"));
                            try {
                                bean.setHits(o.getString("hits"));
                            } catch (JSONException e) {
                                bean.setHits("0");
                            }
                            targetList.add(bean);
                        }
                    } catch (IOException e) {
                        Log.e(getClass().getName(), e.getMessage(), e);
                        return 1;
                    } catch (JSONException e) {
                        Log.e(getClass().getName(), e.getMessage(), e);
                        return 2;
                    } catch (Exception e) {
                        Log.e(getClass().getName(), e.getMessage(), e);
                        return 2;
                    }
                    return 0;
                }

                @Override
                protected void onPostExecute(Integer integer) {
                    isFinish = true;
                    if (integer == 1) {
                        Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                    } else if (integer == 2) {
                        //Toast.makeText(FoodPalaceActivity.this, "返回数据错误", Toast.LENGTH_SHORT).show();
                    } else {
                        httpTopSuccess();
                    }
//                displayPoi();
                }
            };
            task.execute(0);

        } catch (Exception e) {
            System.out.print("莫名其妙饿闪退，只有这样了");
            e.printStackTrace();
        }
    }

    private void searchPoiKey(String radius, String searchKey, final int currentPage, String sortby) {
//        try {
//            new String(searchKey.getBytes("gb2312"),"utf-8");
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
        String url = DataCenter.GET_BAIDU_ADDRESS;
        ArrayList<NameValuePair> getParams = new ArrayList<NameValuePair>();
        getParams.add(new BasicNameValuePair("ak", ak));
        getParams.add(new BasicNameValuePair("location", location));
//        if(catid!=16&&catid!=32&&catid!=49){
//            getParams.add(new BasicNameValuePair("filter", "|status:"+3+","+3+"|catid:"+catid+","+catid));
//        }else {
        getParams.add(new BasicNameValuePair("filter", "|status:" + 3 + "," + 3 + "|mid:" + mid + "," + mid));
//        }
        if (searchKey.equals("")){
            getParams.add(new BasicNameValuePair("q",null));
        }else {
            getParams.add(new BasicNameValuePair("q", "'"+searchKey+"'"));
        }
        getParams.add(new BasicNameValuePair("sortby", sortby));
        getParams.add(new BasicNameValuePair("radius", radius));
        getParams.add(new BasicNameValuePair("page_index", currentPage + ""));
        getParams.add(new BasicNameValuePair("geotable_id", "59254"));
        String getParamsStr = URLEncodedUtils.format(getParams, "UTF-8");

        Log.d(getClass().getName(), "getParamsStr " + getParamsStr);

        url += "?" + getParamsStr;
        Log.e("FoodPalaceAcitvityURL", url);
        final String urll = url;

        AsyncTask<Integer, Integer, Integer> task = new AsyncTask<Integer, Integer, Integer>() {
            @Override
            protected Integer doInBackground(Integer... params) {
                try {
                    HttpGet request = new HttpGet(urll);
                    DefaultHttpClient client = new DefaultHttpClient();
                    client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
                    HttpResponse response = client.execute(request);
                    String resultJsonStr = EntityUtils.toString(response.getEntity());
                    code1 = response.getStatusLine().getStatusCode();
                    Log.d(getClass().getName(), "Response json " + resultJsonStr);
                    Log.e("HttpClient",code1+"----------");
                    if(code1!=200){
                        return 1;
                    }
                    JSONObject rootJsonObject;

                    Log.d(getClass().getName(), "Response json " + resultJsonStr);
                    rootJsonObject = new JSONObject(resultJsonStr);
                    JSONArray jsonArray = rootJsonObject.optJSONArray("contents");

                    ArrayList<PlayBean> targetList = DataCenter.playBeanList;

                    if (currentPage == DataCenter.LISTVIEW_BAIDU_DEFAULT_PAGE) {
                        targetList.clear();
                    }
//                    Log.d("GETPLAYLIST",jsonArray.length()+"");
//            for(int i = 0; i < jsonArray.length(); ++i){ // i从1开始，屏蔽提示信息
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject o = (JSONObject) jsonArray.get(i);
                        PlayBean bean = new PlayBean();
                        bean.setSize(jsonArray.length() + "");
                        try{
                            bean.setThumb(o.getString("thumb"));

                        }catch (JSONException e ){

                        }
                        try {
                            bean.setStar(o.getString("star"));
                        } catch (JSONException e) {

                        }
                        bean.setShopLongitude(o.optJSONArray("location").get(0) + "");
                        bean.setShopLatitude(o.optJSONArray("location").get(1) + "");
                        bean.setTitle(o.getString("title"));
                        bean.setAddress(o.getString("address"));
                        bean.setDistance(o.getString("distance"));
                        bean.setWeight(o.getString("weight"));
                        bean.setItemid(o.getString("itemid"));
                        bean.setCatid(o.getString("catid"));
                        targetList.add(bean);
                    }
                } catch (IOException e) {
                    Log.e(getClass().getName(), e.getMessage(), e);
                    return 1;
                } catch (JSONException e) {
                    Log.e(getClass().getName(), e.getMessage(), e);
                    return 2;
                }
                return 0;
            }


            @Override
            protected void onPostExecute(Integer integer) {
                listView.setEnabled(true);
                isFinish = true;
                if (integer == 1) {
                    listView.onRefreshComplete();
                    listView.onLoadMoreComplete(false);
                    closeProgressDialog();
                    progressBar.setVisibility(View.GONE);
                    Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                    return;
                } else if (integer == 2) {
                    listView.onRefreshComplete();
                    listView.onLoadMoreComplete(false);
                    closeProgressDialog();
                    progressBar.setVisibility(View.GONE);
                   // Toast.makeText(FoodPalaceActivity.this, "返回数据错误", Toast.LENGTH_SHORT).show();
                   // return;
                }
                httpSuccess();
//                displayPoi();
            }
        };
        task.execute(0);
    }

    int code1;

    private void searchPoi1(String radius, int catid, final int currentPage, String sortby) {
        String url = DataCenter.GET_BAIDU_ADDRESS;
        ArrayList<NameValuePair> getParams = new ArrayList<NameValuePair>();
        getParams.add(new BasicNameValuePair("ak", ak));
        getParams.add(new BasicNameValuePair("location", location));
        getParams.add(new BasicNameValuePair("radius", radius));
        Log.d("searchFood", "catid= " + catid + "-----mid= " + mid);
        if (catid != 16 && catid != 32 && catid != 49) {
            getParams.add(new BasicNameValuePair("filter", "|status:" + 3 + "," + 3 + "|catid:" + catid + "," + catid));
        } else {
            getParams.add(new BasicNameValuePair("filter", "|status:" + 3 + "," + 3 + "|mid:" + mid + "," + mid));
        }
        getParams.add(new BasicNameValuePair("sortby", sortby));
        getParams.add(new BasicNameValuePair("page_index", currentPage + ""));
        getParams.add(new BasicNameValuePair("geotable_id", "59254"));

        String getParamsStr = URLEncodedUtils.format(getParams, "UTF-8");

        Log.d(getClass().getName(), "getParamsStr " + getParamsStr);

        url += "?" + getParamsStr;
        Log.e("FoodPalaceAcitvityURL", url);
        final String urll = url;
        try {
            AsyncTask<Integer, Integer, Integer> task = new AsyncTask<Integer, Integer, Integer>() {
                @Override
                protected Integer doInBackground(Integer... params) {
                    try {
                        HttpGet request = new HttpGet(urll);
                        DefaultHttpClient client = new DefaultHttpClient();
                        JSONObject rootJsonObject;
//                        HttpParams parms = new BasicHttpParams();
//                        HttpConnectionParams.setConnectionTimeout(parms, 1);//设置网络超时
//                        HttpConnectionParams.setSoTimeout(parms, 1);//设置网络超时
                        client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
                        HttpResponse response = client.execute(request);
                        String resultJsonStr = EntityUtils.toString(response.getEntity());
                        code1 = response.getStatusLine().getStatusCode();
                        Log.d(getClass().getName(), "Response json " + resultJsonStr);
                        Log.e("HttpClient",code1+"----------");
                        if(code1!=200){
                            return 1;
                        }
                        rootJsonObject = new JSONObject(resultJsonStr);
                        JSONArray jsonArray = rootJsonObject.optJSONArray("contents");
                        ArrayList<PlayBean> targetList = DataCenter.playBeanList;
                        if (currentPage == DataCenter.LISTVIEW_BAIDU_DEFAULT_PAGE) {
                            targetList.clear();
                        }
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject o = (JSONObject) jsonArray.get(i);
                            PlayBean bean = new PlayBean();
                            bean.setSize(jsonArray.length() + "");
                            try {
                                bean.setThumb(o.getString("thumb"));
                            } catch (JSONException e) {

                            }
                            try {
                                bean.setStar(o.getString("star"));
                            } catch (JSONException e) {

                            }
                            bean.setShopLongitude(o.optJSONArray("location").get(0) + "");
                            bean.setShopLatitude(o.optJSONArray("location").get(1) + "");
                            bean.setTitle(o.getString("title"));
                            bean.setAddress(o.getString("address"));
                            bean.setDistance(o.getString("distance"));
                            bean.setWeight(o.getString("weight"));
                            bean.setItemid(o.getString("itemid"));
                            bean.setCatid(o.getString("catid"));
                            targetList.add(bean);
                        }
                    } catch (IOException e) {
//                            closeProgressDialog();
//                            progressBar.setVisibility(View.GONE);
//                            Log.e(getClass().getName(), e.getMessage(), e);
//                            Toast.makeText(FoodPalaceActivity.this,"网络连接超时",Toast.LENGTH_SHORT).show();
                        return 1;
                    } catch (JSONException e) {
//                            Log.e(getClass().getName(), e.getMessage(), e);
                        return 2;
                    } catch (Exception e) {
//                            Log.e(getClass().getName(), e.getMessage(), e);
//                            e.printStackTrace();
                        return 3;
                    }
                    return 0;
                }

                @Override
                protected void onPostExecute(Integer integer) {
                    listView.setEnabled(true);
                    isFinish = true;
                    closeProgressDialog();
                    if(null!=findViewById(R.id.tour_menu_navi2_2)){
                        findViewById(R.id.tour_menu_navi2_2).setEnabled(true);
                    }
                    if (integer == 1) {
                        listView.onLoadMoreComplete(false);
                        listView.onRefreshComplete();
                        progressBar.setVisibility(View.GONE);
                        Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                        return;
                    } else if (integer == 2) {
                        listView.onLoadMoreComplete(false);
                        progressBar.setVisibility(View.GONE);
                        listView.onRefreshComplete();
                       // Toast.makeText(FoodPalaceActivity.this, "返回数据错误", Toast.LENGTH_SHORT).show();
                       // return;
                    } else if (integer == 3) {
                        progressBar.setVisibility(View.GONE);
                        no_content_view.setVisibility(View.VISIBLE);
                        listView.setVisibility(View.INVISIBLE);
                        ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(getText(R.string.listview_msg_error));
                        return;
                    }
                    httpSuccess();
//                displayPoi();
                }
            };
            task.execute(0);
        } catch (RuntimeException e) {

        }
    }


    private void findviews() {

        editTextWithDel = (EditTextWithDel) findViewById(R.id.search_with_del);

        mTextView02 = (AutoTextView) findViewById(R.id.switcher02);

        no_content_view = findViewById(R.id.no_content_view);


        listView = (DragListView) findViewById(R.id.play_listview);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundleData = new Bundle();
                try {
                    bundleData.putSerializable("playBean", targetList.get(position - 1));
                } catch (IndexOutOfBoundsException e) {
                    return;
                }
                Class<?> classz = FoodPalaceDetail.class;
                if (module_type == MODLUE_PLAY) {
                    classz = PlayDetailActivity.class;
                }
                Intent intent = new Intent(FoodPalaceActivity.this, classz);
                intent.putExtras(bundleData);
                intent.putExtra("module_type", module_type);
                try {
                    intent.putExtra("itemid", targetList.get(position - 1).getItemid());
                } catch (IndexOutOfBoundsException e) {
                    e.printStackTrace();
                }
                // catid是死值
                int catid = 0;
                if (module_type == MODULE_FOOD_PALACE) {
                    catid = DataCenter.CATID_FOOD_PALACE;
                } else if (module_type == MODLUE_BUY_STREET) {
                    catid = DataCenter.CATID_BUY_STREAT;
                } else if (module_type == MODLUE_PLAY) {
                    catid = DataCenter.CATID_PLAY;
                }
                intent.putExtra("catid", catid+""); //catid是整形的
                intent.putExtra("catids", targetList.get(position-1).getCatid()+"");
                startActivity(intent);
            }
        });
        listView.setOnRefreshListener(new DragListView.OnRefreshLoadingMoreListener() {
            @Override
            public void onRefresh() {//表示搜索框开启
                if(!isFinish){
                    Toast.makeText(FoodPalaceActivity.this,"正在请求中,请稍后",Toast.LENGTH_SHORT).show();
                    return;
                }
                isFinish=false;
                refresh = 0;
                Log.d("OnRefresh", "dasdasdasdas");
                currentPage = 0;
                if (serachFlag == 1) {
                    currentPage = 0;
                    searchKey = search_with_del.getText().toString() + "";
                    if (searchKey.equals("") || null == searchKey) {
                        searchPoi1(radius, catid, 0, sortby);
                        return;
                    }
                    if (searchKey.length() < 2) {
                        Toast.makeText(FoodPalaceActivity.this, "请输入至少2个关键字", Toast.LENGTH_SHORT).show();
                        listView.onRefreshComplete();
                        return;
                    }
                    searchPoiKey("5000", searchKey, currentPage, sortby);
                } else {
                    searchPoi1(radius, catid, 0, sortby);
                    searchPoi(ak, location, radius, "1", mid);
                }
                flag = true;
                currentPage = DataCenter.LISTVIEW_BAIDU_DEFAULT_PAGE;
            }

            @Override
            public void onLoadMore() {
                if(!isFinish){
                    Toast.makeText(FoodPalaceActivity.this,"正在请求中,请稍后",Toast.LENGTH_SHORT).show();
                    return;
                }
                isFinish=false;
                refresh = 1;
//                listView.setEnabled(false);
                searchKey = search_with_del.getText().toString() + "";
                if (serachFlag == 1) {
                    if (searchKey.length() < 2 && searchKey.length() >= 1) {
                        Toast.makeText(FoodPalaceActivity.this, "请输入至少2个关键字", Toast.LENGTH_SHORT).show();
                        listView.onLoadMoreComplete(false);
                        return;
                    }
                    if (searchKey.equals("") || null == searchKey) {
                        searchPoi1(radius, catid, ++currentPage, sortby);
                        return;
                    }
                    searchPoiKey("5000", searchKey, ++currentPage, sortby);
                } else {
//                    new GetPlayLIst(catid, ak, "59254", location, radius, (++currentPage) + "").execute();
                    if(flag){
                        searchPoi1(radius, catid, ++currentPage, sortby);
                    }else{
                        searchPoi1(radius, catid, ++currentPage, "edittime:-1");
                    }

                }
            }
        });
        progressBar = (ProgressBar) findViewById(R.id.play_inner_progress_bar);
        search_with_del = new EditTextWithDel(this);
        search_with_del = (EditTextWithDel) findViewById(R.id.search_with_del);
        search_confim_button = (ImageButton) findViewById(R.id.search_confim_button);
        search_confim_button.setOnClickListener(this);
        backImageButton = (ImageButton) findViewById(R.id.foodPalaceBack);
        backImageButton.setOnClickListener(this);
    }

    //===================================================底部动画start============================
    private void initBottomMneu() {
        findViewById(R.id.bottom_navi).setVisibility(View.VISIBLE);
        menuBgVew = findViewById(R.id.tour_menuBgVew);
        menuContainer = (LinearLayout) findViewById(R.id.tour_menuContainer_two);
        menuContainer.setVisibility(View.VISIBLE);

        if (module_type == MODLUE_PLAY) {
            menuContainer.setBackgroundResource(R.drawable.food_bottom_bg_no_line);
        }

        for (int i = 0; i < menuContainer.getChildCount(); i++) {
            TextView menuTextView = (TextView) menuContainer.getChildAt(i);
            menuTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    menuOnClick(v);
                }
            });
            if (i == 0) {
                menuTextView.setText("  距离  ");
            } else if (i == 1) {
                menuTextView.setText("好评度");
                if (module_type == MODLUE_PLAY) {
                    menuContainer.removeView(menuTextView);
                }
            }
        }


        //默认选中第一个
        preSelectMenuIndex = 0;


        // 该事件是在组件被加载到界面，并且可以获取到大小的时候调用
        menuContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                // Ensure you call it only once :
                menuContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                // Here you can get the size :)

                TextView firstMenuTextView = (TextView) menuContainer.getChildAt(0);

                Log.d(TAG, "first menu width " + firstMenuTextView.getWidth());

                //menuBgVew.setWidth(firstMenuTextView.getWidth());

                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) menuBgVew.getLayoutParams();
                layoutParams.width = firstMenuTextView.getWidth();
                menuBgVew.setLayoutParams(layoutParams);
            }
        });
    }

    private void menuOnClick(View view) {
        currentPage = DataCenter.LISTVIEW_BAIDU_DEFAULT_PAGE;
        for (int i = 0; i < menuContainer.getChildCount(); i++) {
            TextView menuTextView = (TextView) menuContainer.getChildAt(i);
            menuTextView.setTextColor(getResources().getColor(R.color.font_black));
        }
        ((TextView) view).setTextColor(getResources().getColor(R.color.title_detail_color));

        view_id = view.getId();
        //添加更新操作: (底部四种导航的)
        handle();


        int currentSelectMenuIndex = menuContainer.indexOfChild(view);


        float preOffset = 0;
        for (int i = 0; i < preSelectMenuIndex; i++) {
            preOffset += menuContainer.getChildAt(i).getWidth();
        }


        float newOffset = 0;
        for (int i = 0; i < currentSelectMenuIndex; i++) {
            newOffset += menuContainer.getChildAt(i).getWidth();
        }

        TranslateAnimation translateAnimation = new TranslateAnimation(preOffset, newOffset, 0, 0);
        translateAnimation.setDuration(300);

        int oldWidth = menuBgVew.getWidth();
        int newWidth = view.getWidth();

        float oldScale = ((float) menuContainer.getChildAt(preSelectMenuIndex).getWidth()) / ((float) menuBgVew.getWidth());
        float newScale = ((float) menuContainer.getChildAt(currentSelectMenuIndex).getWidth()) / ((float) menuBgVew.getWidth());

        Log.d(TAG, "oldScale " + oldScale);
        Log.d(TAG, "newScale " + newScale);

        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) menuBgVew.getLayoutParams();
        layoutParams.width = newWidth;
        menuBgVew.setLayoutParams(layoutParams);

        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(translateAnimation);

        animationSet.setFillAfter(true);
        menuBgVew.startAnimation(animationSet);

        preSelectMenuIndex = currentSelectMenuIndex;

    } //===================================================底部动画END============================

    private void handle() {
        if(!HttpUtils.isConnected()){
            Toast.makeText(FoodPalaceActivity.this,"连接网络异常,请稍后重试",Toast.LENGTH_SHORT).show();
            return;
        }

        switch (view_id) {
            case R.id.tour_menu_navi2_1:
                if(!isFinish){
                    Toast.makeText(FoodPalaceActivity.this,"正在请求中,请稍后",Toast.LENGTH_SHORT).show();
                    return;
                }
                alertDialogDistance();
                break;
            case R.id.tour_menu_navi2_2:
                if(!isFinish){
                    Toast.makeText(FoodPalaceActivity.this,"正在请求中,请稍后",Toast.LENGTH_SHORT).show();
                    return;
                }
                showProgressDialog();
                alertDialogHighComment();
                break;
        }
    }


    //列表为空的时候执行
    private void initList() {
        if (targetList == null || targetList.size() <= 0) {
            progressBar.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
//        if (targetList.size() <= 0) {
//            initList();
//        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.d(DataCenter.LOG_INFO, FoodPalaceActivity.class.getSimpleName() + ".onDestroy");
//        DataCenter.playBeanList.clear();
        //删除观察者
        if (mapView != null) {
            mapView.destroy();
        }
        DataCenter.index7 = 4;
    }

    private void findActionBar() {
        actionBarView = (ActionBarView) findViewById(R.id.actionbar);
        actionBarView.setTitle("分类");
        actionBarView.setTitleOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isClose = !isClose;
                if (isClose) {
                    closeTopBar();
                } else { //开启分类条
                    openTopBar();
                }
            }
        });
        actionBarView.setTitleIconIsUp(false);

        checkbox_category = actionBarView.checkBox;
        checkbox_category.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isShownTopBar()) {
                    closeTopBar();
                } else {
                    openTopBar();
                }
                checkbox_category.setChecked(isShownTopBar());
            }
        });
        actionBarView.setTitleIconIsUp(false);
        actionBarView.button_right_icon1.setVisibility(View.VISIBLE);
        actionBarView.button_right_icon1.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.food_search));
        actionBarView.button_right_icon1.setOnClickListener(this);
        actionBarView.button_right_icon2.setVisibility(View.VISIBLE);
        actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.food_map));
        actionBarView.button_right_icon2.setOnClickListener(this);
        editTextWithDel.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return false;
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_right_button_icon1:
                Log.d("touch", "touch me");
                findViewById(R.id.actionbar).setVisibility(View.GONE);
                TranslateAnimation anim = new TranslateAnimation(
                        Animation.RELATIVE_TO_SELF, -1.0f,
                        Animation.RELATIVE_TO_SELF, 0.0f,
                        Animation.RELATIVE_TO_SELF, 0.0f,
                        Animation.RELATIVE_TO_SELF, 0.0f);
                anim.setFillAfter(true);
                anim.setDuration(1000);
                findViewById(R.id.foodPalaceSearch).setVisibility(View.VISIBLE);
                findViewById(R.id.search_with_del).startAnimation(anim);
                serachFlag = 1;
                break;
            case R.id.actionbar_right_button_icon2:
                switchFlag = !switchFlag;
                if (!HttpUtils.isConnected()) {
                    Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (DataCenter.nowLatitude == null || DataCenter.nowLatitude.equals("")) {
                    showProgressDialog();
                    Toast.makeText(FoodPalaceActivity.this, "正在定位中,请稍等...", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (switchFlag) {
                    actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.food_map));
                    hiddenMapview();
                    firstIn = 0;
                } else {
                    actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.delicious_map_04));
                    // 初始化百度地图
                    firstIn = 1;
                    createBaiduMap();
                    initBaiduMapData();
                    displayMapView();
                    jsonbt();
                }
                break;
            case R.id.search_confim_button:
                if (!HttpUtils.isConnected()) {
                    Toast.makeText(FoodPalaceActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (DataCenter.nowLatitude == null || DataCenter.nowLatitude.equals("")) {
                    Toast.makeText(FoodPalaceActivity.this, "正在定位中,请稍等...", Toast.LENGTH_SHORT).show();
                    showProgressDialog();
                    return;
                }
                if(!isFinish){
                    Toast.makeText(FoodPalaceActivity.this, "正在请求中,请稍等", Toast.LENGTH_SHORT).show();
                    return;
                }
                isFinish = false;
                searchKey = search_with_del.getText().toString();
                if (searchKey.length() < 2 && searchKey.length() >= 1) {
                    Toast.makeText(FoodPalaceActivity.this, "请输入至少两个字的关键字", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (location == null || location.equals("")) {
                    Toast.makeText(FoodPalaceActivity.this, "定位还未成功，请重新定位", Toast.LENGTH_SHORT).show();
                    test();
                }
                showProgressDialog();
//                new GetPlaySearch(ak, "59254", location, radius, searchKey, (currentPage) + "",Integer.parseInt(mid)).execute();
                searchPoiKey("5000", searchKey, currentPage, sortby);
                break;
            case R.id.foodPalaceBack: //搜索框的返回按钮
                closeSearch();
                serachFlag = 0;
                currentPage = DataCenter.LISTVIEW_DEFAULT_PAGE;
                break;
        }
    }

    /**
     * 关闭顶部搜索框
     */
    private void closeSearch() {
        TranslateAnimation anim = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, -2.0f,

                Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f);
        anim.setFillAfter(true);
        anim.setDuration(1000);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                findViewById(R.id.actionbar).setVisibility(View.VISIBLE);
                findViewById(R.id.foodPalaceSearch).setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        findViewById(R.id.search_with_del).startAnimation(anim);
    }

    int indexSelect;
    int currentSelect;

    public void alertDialogDistance() {
        final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.show();
        Window window = alertDialog.getWindow();
        window.setContentView(R.layout.food_dialog);
        Button button = (Button) window.findViewById(R.id.food_dialog_bt);
        lv = (ListView) window.findViewById(R.id.food_dialog);
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(FoodPalaceActivity.this, R.layout.food_dialog_item, R.id.food_dialog_distance, fanweis);
        lv.setAdapter(arrayAdapter);

        lv.post(new Runnable() {
            public void run() {
                if (fanweis.length == lv.getChildCount()) {
                    TextView textview = null;
                    ImageView imageView = null;
                    //对ListView中的ChildView进行操纵。。。
                    textview = (TextView) lv.getChildAt(DataCenter.index7).findViewById(R.id.food_dialog_distance);
                    imageView = (ImageView) lv.getChildAt(DataCenter.index7).findViewById(R.id.food_itemIv);
                    textview.setTextColor(getResources().getColor(R.color.title_detail_color));
                    imageView.setVisibility(View.VISIBLE);
                }
            }
        });

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                isFinish =false;
                DataCenter.index7 = position;
                fanwei = (position + 1) * 1000;
                radius = fanwei + "";
                Log.d("fanwei", fanwei + "----------");
                for (int i = 0; i < lv.getChildCount(); i++) {
                    if (i == position) {
                        imageView = (ImageView) lv.getChildAt(position).findViewById(R.id.food_itemIv);
                        tv = (TextView) lv.getChildAt(position).findViewById(R.id.food_dialog_distance);
                        tv.setTextColor(Color.rgb(255, 128, 64));
                        imageView.setVisibility(View.VISIBLE);
                    } else {
                        imageView = (ImageView) lv.getChildAt(i).findViewById(R.id.food_itemIv);
                        tv = (TextView) lv.getChildAt(i).findViewById(R.id.food_dialog_distance);
                        tv.setTextColor(Color.rgb(0, 0, 0));
                        imageView.setVisibility(View.GONE);
                    }
                }
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                currentSelect = DataCenter.index7;

                if (serachFlag == 1) {
                    searchPoiKey(fanwei + "", searchKey, currentPage, sortby);
                } else {
                    if (firstIn == 0) {
                        searchPoi1(fanwei + "", catid, currentPage, sortby);
                    } else {
                        if (currentSelect != indexSelect) {
                            searchPoi1(fanwei + "", catid, currentPage, sortby);
                            indexSelect = currentSelect;
                        } else {
                            searchPoi1(fanwei + "", catid, currentPage, sortby);
                        }
                        firstIn = 1;
                    }
                }
                showProgressDialog();
                // getasyncTask().execute(null);
                alertDialog.dismiss();
                flag = true;
            }
        });
    }

    public void alertDialogHighComment() {
        showProgressDialog();
        if(!isFinish){
            Toast.makeText(FoodPalaceActivity.this,"正在请求中,请稍后",Toast.LENGTH_SHORT).show();
            return;
        }
        isFinish =false;
        if (serachFlag == 1) {
//            if (index == 1) {
                searchPoiKey(radius, searchKey, 0, "star:-1");
//                index = 2;
//            } else if (index == 2) {
//                new GetPlaySearch(Integer.parseInt(mid), ak, "59254", location, radius, searchKey, (currentPage) + "", "star:-1").execute();
//                searchPoiKey("5000", searchKey, 0, "star:-1");
//                index = 1;
//            }
        } else {
//            if (index == 1) {
//                new GetPlayLIst(catid, ak, "59254", location, radius, currentPage + "", "star:1").execute();
                searchPoi1(radius, catid, currentPage, "star:-1");
//                index = 2;
//            } else if (index == 2) {
//                new GetPlayLIst(catid, ak, "59254", location, radius, currentPage + "", "star:-1").execute();
//                searchPoi1(radius, catid, currentPage, "star:-1");
//                index = 1;
//            }
        }
    }

    public void httpTopSuccess() {
        ArrayList<PlayBean> topBeanList = DataCenter.playTopBeansTopList;
        mTextView02.setData3(topBeanList);
        mTextView02.startRolling();
    }

    public void QuickSort(int left, int right, int index) {
        int i, j, k;
        long Pivot;
        long Temp;

        i = left;
        j = right;

        Pivot = Long.parseLong(targetList.get(left).getCreate_time());
        if (i < j) {
            do {
                while (Long.parseLong(targetList.get(i).getCreate_time()) < Pivot && i < right) {
                    i++;
                }
                while (Long.parseLong(targetList.get(j).getCreate_time()) > Pivot && j > left) {
                    j--;
                }
                if (i < j) //exchange a[i] and a[j]
                {
                    Temp = Long.parseLong(targetList.get(i).getCreate_time());
//                    a[i] = a[j];
                    targetList.get(i).setCreate_time(targetList.get(j).getCreate_time());
//                    a[j] = Temp;
                    targetList.get(j).setCreate_time(Temp + "");
                }
            } while (i < j);
            if (i > j) {
//                Temp = a[left]; // exchange a[Left] and a[j]
                Temp = Long.parseLong(targetList.get(left).getCreate_time());
//                a[left] = a[j];
                targetList.get(left).setCreate_time(targetList.get(j).getCreate_time());
//                a[j] = Temp;
                targetList.get(j).setCreate_time(Temp + "");
            }
            QuickSort(left, j - 1, index); // left
            QuickSort(j + 1, right, index); // right

        }
    }


    public void httpSuccess() {
        closeProgressDialog();
        if (!HttpUtils.isConnected()) {
            progressBar.setVisibility(View.GONE);
            no_content_view.setVisibility(View.VISIBLE);
        }
        progressBar.setVisibility(View.GONE);
        try {
            targetList = DataCenter.playBeanList;//类表数据
//        QuickSort(0,targetList.size()-1,targetList.size());

            if (serachFlag != 1) {
                if(isFirst==0){
                    if (module_type == MODLUE_PLAY) {
                        adapter = new PalyListAdapter(this, targetList);
                        listView.setAdapter(adapter);
                        isFirst=1;
                    } else {
                        adapter = new FoodPalaceAdapter(this, targetList);
                        listView.setAdapter(adapter);
                        isFirst=1;
                    }
                }else {
                    adapter.notifyDataSetChanged();
                }
            } else {
                if(isFirst==0){
                    if (module_type == MODLUE_PLAY) {
                        adapter = new PalyListAdapter(this, targetList);
                        listView.setAdapter(adapter);
                    } else {
                        adapter = new FoodPalaceAdapter(this, targetList);
                        listView.setAdapter(adapter);
                    }
                    isFirst=1;
                }else {
                    adapter.notifyDataSetChanged();
                }
            }
            Log.d("Refresh", refresh + "dadasdasdasd");
            if (refresh == 1) {
                adapter.notifyDataSetChanged();
            } else {
                listView.setAdapter(adapter);
                refresh = 0;
            }

            if ((targetList == null || targetList.size() < 1)) {
                no_content_view.setVisibility(View.VISIBLE);
                listView.setVisibility(View.INVISIBLE);
                ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText("暂时没有数据");
            } else {
                listView.setVisibility(View.VISIBLE);
                no_content_view.setVisibility(View.GONE);
            }

            if (firstIn == 1) {
                if (null != poiOverlay) {
                    poiOverlay.removeAll();
                }
                if (null != targetList && targetList.size() != 0) {
                    targetList.clear();
                }
                mapView.refresh();
                jsonbt();
            }
        } catch (IndexOutOfBoundsException e) {

        }

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                listView.onRefreshComplete();
                listView.onLoadMoreComplete(false);
            }
        }, 1000);
    }

    private void initCategoryData() {
        data = new ArrayList<Map<String, String>>();

        TreeMap<String, String> map = null;

        String[] categorys = null;
        switch (module_type) {
            case MODULE_FOOD_PALACE:
                categorys = getResources().getStringArray(R.array.foodCategory);
                break;
            case MODLUE_BUY_STREET:
                categorys = getResources().getStringArray(R.array.buystreetCategory);
                break;
            case MODLUE_PLAY:
                categorys = getResources().getStringArray(R.array.playCategory);
        }

        for (int i = 0; i < categorys.length; ++i) {
            map = new TreeMap<String, String>();
            if (i == 0) {
                map.put("img", "" + DataCenter.commmon_category_img[0]);
            } else {
                map.put("img", "" + DataCenter.commmon_category_img[1]);
            }
            map.put("title", categorys[i] + "...");
            data.add(map);
        }
    }

    private void initCategoryView() {
        categoryListview = (ListView) findViewById(R.id.category_listview);

        String[] from = new String[]{"img", "title"};
        int[] to = new int[]{R.id.category_icon, R.id.category_title};
        simpleAdapter = new SimpleAdapter(this, data, R.layout.category_listview_item, from, to);
        categoryListview.setAdapter(simpleAdapter);
        categoryListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                itemParent = view;
                TextView textview = (TextView) itemParent.findViewById(R.id.category_title);
                textview.setTextColor(getResources().getColor(R.color.title_detail_color));
                simpleAdapter.notifyDataSetChanged();
                actionBarView.setTitle(data.get(i).get("title").replace("...", ""));
                DataCenter.playTopBeansTopList.clear();
                currentPage = 0;
                isClose = true;
                closeTopBar();
                selectModuleCatId(i);
                if (i == 0) {
//                    new GetPlayLIst(mid, ak, "59254", location, radius, currentPage + "").execute();
                    searchPoi1(radius, catid, currentPage, "edittime:-1");
                } else {
                    selectModuleCatId(i);
//                    new GetPlayLIst(catid, ak, "59254", location, radius, currentPage + "").execute();
                    searchPoi1(radius, catid, currentPage, "edittime:-1");
                }
                showProgressDialog();
            }
        });
    }

    @Override
    protected void openTopBar() {
        actionBarView.setTitleIconIsUp(true);

        initCategoryView();

        categoryListview.setVisibility(View.VISIBLE);
        categoryListview.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_in));
    }

    @Override
    protected void closeTopBar() {

        actionBarView.setTitleIconIsUp(false);

        categoryListview.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_out));
        categoryListview.setVisibility(View.GONE);
    }


    @Override
    protected boolean isShownTopBar() {
        return categoryListview.getVisibility() == View.VISIBLE;
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d("dasdasdasdasdas", "" + editTextWithDel.imgAble + "");
        if (editTextWithDel.imgAble != null && event.getAction() == MotionEvent.ACTION_UP && serachFlag == 1) {
            Log.d("dddddddddddddddddddd", "dasdasdasdadas");
            TranslateAnimation anim = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, -2.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
            anim.setFillAfter(true);
            anim.setDuration(1000);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    findViewById(R.id.actionbar).setVisibility(View.VISIBLE);
                    findViewById(R.id.foodPalaceSearch).setVisibility(View.GONE);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            findViewById(R.id.search_with_del).startAnimation(anim);
            serachFlag = 0;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
            if (isShownTopBar()) {
                actionBarView.checkBox.setChecked(false);
                isClose = true;
                closeTopBar();
                return false;
            }

            if (editTextWithDel.imgAble != null && event.getAction() == MotionEvent.ACTION_UP && serachFlag == 1) {
                Log.d("dddddddddddddddddddd", "dasdasdasdadas");
                TranslateAnimation anim = new TranslateAnimation(
                        Animation.RELATIVE_TO_SELF, 0.0f,
                        Animation.RELATIVE_TO_SELF, -2.0f,

                        Animation.RELATIVE_TO_SELF, 0.0f,
                        Animation.RELATIVE_TO_SELF, 0.0f);
                anim.setFillAfter(true);
                anim.setDuration(1000);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        findViewById(R.id.actionbar).setVisibility(View.VISIBLE);
                        findViewById(R.id.foodPalaceSearch).setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                findViewById(R.id.search_with_del).startAnimation(anim);
                serachFlag = 0;
                return false;
            }

        }
        return super.dispatchKeyEvent(event);
    }


    //选择模块类别 catid
    private void selectModuleCatId(int i) {
        switch (module_type) {
            case MODULE_FOOD_PALACE:
                catid = DataCenter.foodPalace_category_id[i];
                mid = "16";
                DataCenter.rolling_current_module_id = DataCenter.moduleFlag.foodpalace;
                break;
            case MODLUE_BUY_STREET:
                catid = DataCenter.buystreet_category_id[i];
                mid = "32";
                DataCenter.rolling_current_module_id = DataCenter.moduleFlag.buystreet;
                break;
            case MODLUE_PLAY:
                catid = DataCenter.play_category_id[i];
                mid = "49";
                DataCenter.rolling_current_module_id = DataCenter.moduleFlag.play;
                break;
        }

    }

    //--------------------------------------地图各种操作start----------------------------------------///
    private MapView mapView = null;
    private MapController mapController;
    private ActionBarView actionBarView;
    //先写死，最后要改的经纬度
    private Double nowLongitude = DataCenter.nowLongitude;
    private Double nowLatitude = DataCenter.nowLatitude;
    private Double shopLongitude;
    private Double shopLatitude;
    private int maxLat = 0;
    private int minLat = 0;
    private int maxLon = 0;
    private int minLon = 0;
    private HttpGet request;
    private DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
    private String resultStr;
    private int size = 0;
//    private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    private PoiOverlay poiOverlay;
    private PoiOverlay poiOverlay1;
    private String title;
    private String tel;
    private int a = 0;
    private int selectedPoiItemIndex;
    private MyLocationOverlay myLocationOverlay;
    private LayoutInflater inflater;
    private String address;
    private String thumb;
    private String star;
    private PlayBean bean;
//    private ArrayList<PlayBean> listBean = new ArrayList<PlayBean>();

    private void createBaiduMap() {

        nowLatitude = DataCenter.nowLatitude;
        nowLongitude = DataCenter.nowLongitude;


        myLocationOverlay = new MyLocationOverlay(mapView);
        LocationData locationData = new LocationData();
        try {
            locationData.latitude = nowLatitude;
            locationData.longitude = nowLongitude;
            myLocationOverlay.setData(locationData);
        } catch (NullPointerException e) {
            Toast.makeText(FoodPalaceActivity.this, "您点的太快了", Toast.LENGTH_SHORT).show();
            return;
        }

        try {
            if (mapView != null) {
                if (myLocationOverlay != null) {
                    if (mapView.getOverlays().size() >= 1) {
                        mapView.getOverlays().remove(myLocationOverlay);
                    }
                }
            }
        } catch (NullPointerException e) {

        }

        //添加图层
        mapView.getOverlays().add(myLocationOverlay);

        mapView.refresh();
    }

    public void initBaiduMapData() {
        Log.d("initBaiduMapData", nowLatitude + "--------" + nowLongitude);
        try {
            GeoPoint point = new GeoPoint((int) (nowLatitude * 1E6), (int) (nowLongitude * 1E6));
            mapController.setCenter(point);//设置地图中心点
            mapController.setZoom(12);//设置地图zoom级别
        } catch (NullPointerException e) {
            Toast.makeText(FoodPalaceActivity.this, "您点的太快了", Toast.LENGTH_SHORT).show();
            return;
        }

    }

    //待解决如何给图片上加文字
    public void displayPoi() {
        if (targetList.size() == 0) {
            GeoPoint point = new GeoPoint((int) (nowLatitude * 1E6), (int) (nowLongitude * 1E6));
            mapController.setCenter(point);//设置地图中心点
            mapController.setZoom(12);//设置地图zoom级别
            return;
        }
        Log.d("displayPoi", "displayPoi" + "  " + targetList.size());
        switch (module_type) {
            case MODULE_FOOD_PALACE:
                mark1 = getResources().getDrawable(R.drawable.food);
                break;
            case MODLUE_BUY_STREET:
                mark1 = getResources().getDrawable(R.drawable.buystreet);
                break;
            case MODLUE_PLAY:
                mark1 = getResources().getDrawable(R.drawable.play);
                break;
        }

        poiOverlay = new PoiOverlay(mark1, mapView);
        for (int i = 0; i < targetList.size(); i++) {
//            Log.d("shopLongitude", targetList.get(i).getShopLongitude() + "   " + "shopLongitude" + list.get(i).get("shopLongitude"));
            GeoPoint p = new GeoPoint((int) (Double.parseDouble(targetList.get(i).getShopLatitude() + "") * 1E6),
                    (int) ((Double.parseDouble(targetList.get(i).getShopLongitude() + "") * 1E6)));
            Log.d("displayPoi", p.getLatitudeE6() + " and " + p.getLongitudeE6());
            PoiItem item1 = new PoiItem(p, "item1", "item1");
            item1.setMarker(mark1);
            poiOverlay.addItem(item1);
        }

        for (int i = 0; i < poiOverlay.getAllItem().size(); i++) {
            OverlayItem item = (OverlayItem) poiOverlay.getAllItem().get(i);
            GeoPoint geoPoint = item.getPoint();
            int lat = geoPoint.getLatitudeE6();
            int lon = geoPoint.getLongitudeE6();
            maxLat = Math.max(lat, maxLat);
            minLat = Math.min(lat, minLat);
            maxLon = Math.max(lon, maxLon);
            minLon = Math.min(lon, minLon);
        }
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (maxLat != 0 && minLat != 0 && maxLon != 0 && minLon != 0) {
                    mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
                    mapController.animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2));
                    mapView.refresh();
                }
            }
        }, 300);
        mapView.getOverlays().add(poiOverlay);
    }

    public void jsonbt() {
        try {
            for (int i = 0; targetList != null && i < targetList.size(); i++) {
                PlayBean playBean = targetList.get(i);
                shopLatitude = Double.parseDouble(playBean.getShopLatitude());
                shopLongitude = Double.parseDouble(playBean.getShopLongitude());
                Log.d("BaiduLongitude", shopLatitude + "-----" + shopLongitude);
                Log.d("jsonbtListSize", targetList.size() + "  BaiduActivityListSize  ");
                if (nowLatitude > shopLatitude) {
                    maxLat = (int) (nowLatitude * 1E6);
                    minLat = (int) (shopLatitude * 1E6);
                } else {
                    minLat = (int) (nowLatitude * 1E6);
                    maxLat = (int) (shopLatitude * 1E6);
                }

                if (nowLongitude > shopLongitude) {
                    maxLon = (int) (nowLongitude * 1E6);
                    minLon = (int) (shopLongitude * 1E6);
                } else {
                    maxLon = (int) (shopLongitude * 1E6);
                    minLon = (int) (nowLongitude * 1E6);
                }
            }
            displayPoi();
            mapView.refresh();
        } catch (NullPointerException e) {
            Toast.makeText(FoodPalaceActivity.this, "您点的太快了", Toast.LENGTH_SHORT).show();
        }
    }


    class PoiOverlay extends ItemizedOverlay {

        public PoiOverlay(Drawable drawable, MapView mapView) {
            super(drawable, mapView);
        }

        @Override
        public boolean onTap(GeoPoint geoPoint, MapView mapView) {
            Log.d("OnTap", geoPoint.getLatitudeE6() + "  this is onTap");
            return super.onTap(geoPoint, mapView);
        }

        @Override
        protected boolean onTap(int i) {
            Log.d("OnTap", i + "  点点点啊");
            selectedPoiItemIndex = i;
            PopupOverlay popupOverlay = new PopupOverlay(mapView, new PopupClickListener() {
                @Override
                public void onClickedPopup(int i) {
                    Log.d("popupOnTap", i + "");
                    Intent intent = new Intent(FoodPalaceActivity.this, FoodPalaceDetail.class);
                    Bundle bundle = new Bundle();

//                    Log.d("FoodPalaceDetailItemidBaidu", listBean.get(selectedPoiItemIndex).getItemid() + "------");
                    bundle.putSerializable("itemid", targetList.get(selectedPoiItemIndex).getItemid());
                    bundle.putSerializable("catid", targetList.get(selectedPoiItemIndex).getCatid());
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
            PoiItem item = (PoiItem) poiOverlay.getItem(i);
            if (null == inflater) {
                inflater = getLayoutInflater();
            }
            View popup = inflater.inflate(R.layout.baidu_popup, null);
            TextView titleTextView = (TextView) popup.findViewById(R.id.baidupop);
            titleTextView.setText((String) targetList.get(i).getTitle());
            popupOverlay.showPopup(popup, item.getPoint(), item.getMarker().getIntrinsicHeight());
            return super.onTap(i);
        }
    }

    /**
     * 显示百度地图
     */
    private void displayMapView() {
        findViewById(R.id.foodDetail_view_data).setVisibility(View.GONE);
        findViewById(R.id.baiduMapsView).setVisibility(View.VISIBLE);
    }

    /**
     * 隐藏百度地图
     */
    private void hiddenMapview() {
        findViewById(R.id.foodDetail_view_data).setVisibility(View.VISIBLE);
        findViewById(R.id.baiduMapsView).setVisibility(View.GONE);
    }

    class PoiItem extends OverlayItem {

        private int type;

        public PoiItem(GeoPoint geoPoint, String s, String s2) {
            super(geoPoint, s, s2);
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

    }
    //--------------------------------------地图各种操作end----------------------------------------///


    /**
     * 显示列表数据
     */
    private void showCurrentDataView() {
        listView.setVisibility(View.VISIBLE);
        no_content_view.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
    }

    /**
     * 正在加载，隐藏列表
     */
    private void showCurrentProgressView() {
        listView.setVisibility(View.GONE);
        no_content_view.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);
    }

    /**
     * 提示没有数据
     */
    private void showCurrentEmptyMsgView() {
        listView.setVisibility(View.GONE);
        ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText("没有数据");
        no_content_view.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
    }
}
